using UnityEngine;

namespace SunshineFarmWord
{
    public class StateMachine
    {
        // 保存当前状态
        protected IState currentState;

        // 切换状态
        public void ChangeState(IState newState)
        {
            //
            currentState?.Exit();

            currentState = newState;

            currentState.Enter();
        }

        // 输入处理
        public void HandleInput()
        {
            currentState?.HandleInput();
        }

        // 更新
        public void Update()
        {
            currentState?.Update();
        }

        // 物理更新
        public void PhysicsUpdate()
        {
            currentState?.PhysicsUpdate();
        }

        public void OnAnimationEnterEvent()
        {
            currentState?.OnAnimationEnterEvent();
        }

        public void OnAnimationExitEvent()
        {
            currentState?.OnAnimationExitEvent();
        }

        public void OnAnimationTransitionEvent()
        {
            currentState?.OnAnimationTransitionEvent();
        }

        public void OnTriggerEnter2D(Collider2D collider)
        {
            currentState?.OnTriggerEnter2D(collider);
        }

        public void OnCollisionEnter2D(Collision2D collision)
        {
            currentState?.OnCollisionEnter2D(collision);
        }

        public void OnTriggerExit2D(Collider2D collider)
        {
            currentState?.OnTriggerExit2D(collider);
        }

        public void OnCollisionExit2D(Collision2D collision)
        {
            currentState?.OnCollisionExit2D(collision);
        }

        //
        public void OnTriggerStay2D(Collider2D collider)
        {
            currentState?.OnTriggerStay2D(collider);
        }
    }
}
